package org.cheetah.core.action.impl;

import org.cheetah.core.action.Action;
import org.cheetah.core.action.ActionContext;
import org.cheetah.core.exchange.Exchange;

public class DefaultActionContext implements ActionContext {
	private Action action;

	private Object attachment;

	DefaultActionContext next;

	DefaultActionContext prev;

	public DefaultActionContext(Action action) {
		this.action = action;
		this.attachment = null;

		this.next = null;
		this.prev = null;
	}

	public Action getAction() {
		return action;
	}

	public Object getAttachment() {
		return attachment;
	}

	public void setAttachment(Object attachment) {
		this.attachment = attachment;
	}

	public void process(Exchange exchange) throws Exception {
		if (next != null) {
			if (exchange.hasOut()) {
				exchange.setIn(exchange.getOut());
				exchange.setOut(null);
			}

			next.process(exchange);
		}
	}
}
